package microservicedemo.productservice.mapper;

import microservicedemo.productservice.po.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;


import java.util.List;

public interface ProductMapper {
    @Select("select p.product_name as productName,p.price as price from product p where id = #{productId}")
    Product findByProductId(@Param("productId") Long productId);

    @Select("select p.id,p.product_name as productName,p.price as price, p.stock as stock from product p")
    List<Product> queryAllProduct();

    @Insert("insert into product(product_name,price,stock)"+"values(#{productName},#{price},#{stock})")
    boolean addNewProduct(@RequestBody Product product);

    @Delete("delete from product where product.id=#{productId}")
    boolean deleteProduct(@PathVariable Long productId);

    @Update("update product set product_name=#{productName},price = #{price},stock=#{stock} where id =#{id}")
    boolean updateProduct(@RequestBody Product product);
}
